package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import java.util.Arrays;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 利用状态类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum UseOrderStatusEnum {

  /** 待处理 */
  UNDER_REVIEW(1, "审核中"),
  PASSED(2, "借阅中"),
  REFUSE(3, "拒绝"),
  FINISHED(4, "已完成"),
  WAIT_RECEIVE(5, "待领取"),
  LATE(6, "已逾期"),
  ABNORMAL(7, "异常终止");

  private Integer code;
  private String desc;

  public static UseOrderStatusEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到利用类型：" + type));
  }

  @JsonCreator
  public static UseOrderStatusEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
